﻿using System;
using MarriageFertility.Behaviors;
using MarriageFertility.Helpers;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;

namespace MarriageFertility.Actions;

public static class PregnancyAction
{
    public static void TryPregnancy(this Hero hero)
    {
        if (!hero.IsFemale || hero.IsPregnant) return;
        try
        {
            float chance = Campaign.Current.Models.PregnancyModel.GetDailyChanceOfPregnancyForHero(hero);
            if (MBRandom.RandomFloat < chance)
            {
                hero.IsPregnant = true;
                CustomerPregnancyCampaignBehavior pregnancyBehavior =
                    Campaign.Current.GetCampaignBehavior<CustomerPregnancyCampaignBehavior>();
                pregnancyBehavior.RecordPregnancyData(hero, Hero.MainHero);
            }
        }
        catch (Exception ex)
        {
            Log.ErrorMessage(ex.StackTrace);
        }
    }
}